home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13122 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  52 lines

  1. Path: news.umbc.edu!not-for-mail
  2. From: schlein@umbc.edu (Jonas J. Schlein)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help!  Can't read input from keyboard!
  5. Date: 4 Apr 1996 14:17:47 -0500
  6. Organization: University of Maryland Baltimore County
  7. Message-ID: <4k178r$kse@umbc9.umbc.edu>
  8. References: <4jq0ts$5mh@taniemarie.solon.com>
  9. NNTP-Posting-Host: umbc9.umbc.edu
  10. NNTP-Posting-User: schlein
  11.  
  12. Peter Seebach <seebs@taniemarie.solon.com> wrote:
  13. |> I guess I thought I knew C, but maybe not.  The following program compiles
  14. |> without error with
  15.  
  16. Maybe not ;-).
  17.  
  18. |> gcc -g -O -Wa,ll -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes
  19.  
  20. It does? Well even so since when is compiler acceptance equivalent to
  21. program correctness?
  22.  
  23. |> but doesn't print 3!  I thought scanf and printf were asymptotic.
  24.  
  25. Asymptotic?
  26.  
  27. |>     #include <stdio.h>
  28. |> 
  29. |>     int main(void) {
  30. |>         int i = 0;
  31. |> 
  32. |>         (void) sscanf, "3", "%d", i;
  33. |> 
  34. |>         (void) printf, "%d", i;
  35.  
  36. It's customary to enclose arguments to a function in ()'s. Additionally
  37. the third argument to sscanf should be a pointer to int so put a & before
  38. that 'i'.
  39.  
  40. |>         return 0;
  41. |>     }
  42. |> 
  43. |> Can anyone help?  I have cast sscanf() to void to prevent it from
  44. |> erroring.
  45.  
  46. Only thing the void is doing is ignoring the return argument from those
  47. functions which aren't being invoked properly.
  48. -- 
  49. "If it wasn't for C, we would be using BASI, PASAL, and OBOL."
  50.  
  51. Jonas J. Schlein  (schlein@gl.umbc.edu)
  52.